package com.nbsaas.boot.controller.lock;

import java.util.concurrent.ConcurrentHashMap;

public class SimpleMemoryLockService implements LockService {

    private final ConcurrentHashMap<String, Boolean> lockMap = new ConcurrentHashMap<>();

    @Override
    public boolean lock(String key) {
        return lockMap.putIfAbsent(key, true) == null;
    }

    @Override
    public boolean unlock(String key) {
        return lockMap.remove(key) != null;
    }

    @Override
    public boolean isLocked(String key) {
        return lockMap.containsKey(key);
    }
}
